{include file='/public/header'}
  <body>
    <div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">分类管理</a>
        <a>
          <cite>分类列表</cite></a>
      </span>
      <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
    </div>
    <div class="x-body">
      <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so" action="{:url('type/index')}" method="post">
          <input type="text" name="search_name" value="{$search_name}"  placeholder="请输入分类名" autocomplete="off" class="layui-input">
          <button class="layui-btn"  lay-submit lay-filter="type_sreach"><i class="layui-icon">&#xe615;</i></button>
        </form>
      </div>
      <xblock>
        <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>
        <button class="layui-btn" onclick="add()"><i class="layui-icon"></i>添加</button>
        <span class="x-right" style="line-height:40px">共有数据：{$total} 条</span>
      </xblock>
      <table class="layui-table">
        <thead>
          <tr>
            <th>
              <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
            </th>
            <th>ID</th>
            <th>分类名称</th>
            <th>PID</th>
            <th>PATH</th>
            <th>状态</th>
            <th>操作</th>
        </thead>
        <tbody>
        {volist name="result" id='vo'}
          <tr>
            <td>
              <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='2'><i class="layui-icon">&#xe605;</i></div>
            </td>
            <td>{$vo.id}</td>
            <td>{$vo.name}</td>
            <td>{$vo.pid}</td>
            <td>{$vo.path}</td>
            <td class="td-status">{$vo.status==0?'正常':'<span style="color:red;"><i class="layui-icon">&#xe756;</i>热销</span>'}</td>
            <td class="td-manage">
              <a title="编辑"  onclick="edit({$vo.id})" href="javascript:;">
                <i class="layui-icon">&#xe642;</i>
              </a>
              <a title="删除" onclick="del({$vo.id})" href="javascript:;">
                <i class="layui-icon">&#xe640;</i>
              </a>
            </td>
          </tr>
        {/volist}
        </tbody>
      </table>
    <script>
      layui.use(['layer','form'], function(){
        $ = layui.jquery;
        layer = layui.layer;
        form = layui.form;
        form.on('submit(type_search)', function(data){
          layer.msg(JSON.stringify(data.field));
          return false;
        });
      });
      //添加分类
      function add(id,w,h){
          if (w == null || w == '') {
              w=($(window).width()*0.9);
          };
          if (h == null || h == '') {
              h=($(window).height() - 50);
          };
          layer.open({
              type: 2,
              area: [w+'px', h +'px'],
              fix: false, //不固定
              maxmin: true,
              shadeClose: true,
              shade:0.4,
              title: '添加分类',
              content: '{:url("type/add")}'
          });
      }
      function edit(id,w,h){
          if (w == null || w == '') {
              w=($(window).width()*0.9);
          };
          if (h == null || h == '') {
              h=($(window).height() - 50);
          };
          layer.open({
              type: 2,
              area: [w+'px', h +'px'],
              fix: false, //不固定
              maxmin: true,
              shadeClose: true,
              shade:0.4,
              title: '分类编辑',
              content: '{:url("type/edit")}?id='+id
          });
      }
      /*关闭弹出框口*/
      function x_admin_close(){
          var index = parent.layer.getFrameIndex(window.name);
          parent.layer.close(index);
      }
      
      //删除
      function del(id){
        layer.confirm('确定要删除吗？', {
          btn: ['确定','取消']
        }, function(){
          $.post('{:url("type/delete")}',{'id':id},function(res){
            if(res.code>0){
              layer.alert(res.msg,{icon:2});
            }else{
              layer.msg(res.msg);
              setTimeout(function(){window.location.reload();},1000);
            }
          },'json');
        });
      }
    </script>

</html>